﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using ModuleDALCore;
namespace DAL
{
    public class Sys_UserDAO:DALBase
    {
        private String _SpName ;
        public String SpName
        {
            get { return "SpSys_User"; }
            set { _SpName = "SpSys_User"; }
        }
        public Sys_UserDAO()
        {
            OpenConnect();
        }
        public DataTable IsLogin(Sys_User user)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName((Sys_User)user, null), ConvertClassToArray.GetValues((Sys_User)user, 0));
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
            return dt;
        }

        public bool Insert(Object obj)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName((Sys_User)obj, null), ConvertClassToArray.GetValues((Sys_User)obj, 1)) == 1);
            }
            catch(Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public bool Delete(Object obj)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName((Sys_User)obj, null), ConvertClassToArray.GetValues((Sys_User)obj, 1)) == 1);
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public bool Update(Object obj)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName((Sys_User)obj, null), ConvertClassToArray.GetValues((Sys_User)obj, 1)) == 1);
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public DataTable SelectOne(int Code)
        {
            return null;
        }
        public DataTable SelectOne(Object obj)
        {
            try
            {
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName((Dec_ChangeRoom)obj, null), ConvertClassToArray.GetValues((Dec_ChangeRoom)obj, 4));
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
        public DataTable SelectALL()
        {
            try
            {
                Dec_ChangeRoom cc = new Dec_ChangeRoom();
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(cc, null), ConvertClassToArray.GetValues(cc, 4));
            }
            catch (Exception ex)
            {
                throw new InvalidProgramException(ex.Message);
            }
        }
    }
    }

